import { createRouter, createWebHashHistory } from "vue-router";
import { setDocumentTitle } from "@/utils/index";

export const constantRoutes = [
  {
    path: "/",
    meta: { title: "首页" },
    component: () => import("@/views/index.vue"),
  },
  {
    path: "/ueDemo",
    meta: { title: "ueDemo" },
    component: () => import("@/views/ueDemo.vue"),
    children: [
      {
        path: "ue_1",
        name: "ue_1",
        meta: { title: "ue_1" },
        component: () => import("@/utils/ueTool/ue4Player/ue4Player.vue"),
      },
      {
        path: "ue_2",
        name: "ue_2",
        meta: { title: "ue_2" },
        component: () => import("@/components/ue4PlayerDefault.vue"),
      },
      {
        path: "ue_3",
        name: "ue_3",
        meta: { title: "ue_3" },
        component: () => import("@/components/ue4PlayerPeer.vue"),
      },
    ],
  },
  {
    path: "/function",
    meta: { title: "Function" },
    component: () => import("@/views/function.vue"),
  },
  {
    path: "/about",
    meta: { title: "About" },
    component: () => import("@/views/about.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
});

router.beforeEach((to, from, next) => {
  setDocumentTitle(to.meta.title);
  next();
});

export default router;
